package alert

import (
	"fmt"
	"net/http"
	"bytes"
)

func (e MonitorAlertEntry)sendDingDing(trigger triggerEntry){

	fmt.Printf("debug dingding")

	dingdingUrl := "https://oapi.dingtalk.com/robot/send?access_token=3c3b0316d03f3c02a09a520eaea815b26c9e156415e505599b31c12b565ad752"

//	formt := `
//{
//    "actionCard": {
//        "title": "%s",
//        "text": "主机: %s\n
//等级: warning\n
//阈值: %s\n
//当前值: %f\n
//告警时间: %s\n",
//        "hideAvatar": "0",
//        "btnOrientation": "0",
//        "singleTitle" : "阅读全文",
//        "singleURL" : "https://www.dingtalk.com/"
//    },
//    "msgtype": "actionCard"
//}
//`

message := `
{
     "msgtype": "markdown",
     "markdown": {
         "title":"%s",
         "text":"
内容:%s\n
主机: %s\n
等级: warning\n
指标：%s\n
阈值: %f\n
符号: %s\n
当前值: %f\n
告警时间: %s\n"
     },
    "at": {
        "atMobiles": [
            "13625298324"
        ], 
        "isAtAll": false
    }
 }
`

	body := fmt.Sprintf(message,e.Title,e.Title,e.Ip,trigger.currentStatus.query,trigger.specify,trigger.logic,trigger.currentStatus.result,e.AlertTime)

	jsonvalue := []byte(body)
	resp,err := http.Post(dingdingUrl,"application/json",bytes.NewBuffer(jsonvalue))
	if err != nil{
		fmt.Println("send failed")
	}
	fmt.Println("send successed")
	fmt.Println(resp)

}


